package hanjia;

import java.util.ArrayList;
import java.util.List;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/12-下午8:28
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode77 {
    public static List<List<Integer>> combine(int n, int k) {

        int start=0;
        List<Integer> result = new ArrayList<>();
        List<List<Integer>>  results = new ArrayList<>();

        backtracking(n,k,start,result,results);
        return results;

    }

    private static void backtracking(int n, int k, int start, List<Integer> result, List<List<Integer>> results) {
        if (result.size()==k){
            results.add(new ArrayList<>(result));
          return;
        }


        for (int i=start;i<n;i++){
            result.add(i+1);
            backtracking(n,k,i+1,result,results);
            result.remove(result.size()-1);

        }

    }
}
